#include "Protocol.h"
#include <cstring>

char *RepProtocol::SerializeMSGType(char *ptr, unsigned char MSGTypes)
{
	return Serialize::Serialize8(ptr, MSGTypes);
}

char *RepProtocol::DeserializeMSGType(char *ptr, unsigned char &MSGTypes)
{
	return Serialize::Deserialize8(ptr, MSGTypes);
}

char *RepProtocol::DeserializeEntryMSG(char *ptr, PlayerMatching &playerInitizeInput)
{
	ptr = Serialize::Deserialize8(ptr, playerInitizeInput.TeamType);
	ptr = Serialize::Deserialize8(ptr, playerInitizeInput.NameSize);
	for (size_t i = 0; i < playerInitizeInput.NameSize && i < sizeof(playerInitizeInput.Name); i++)
		ptr = Serialize::Deserialize8(ptr, playerInitizeInput.Name[i]);
	return ptr;
}

char *RepProtocol::SerializeEntryMSG(PlayerMatching &playerInitizeInput, char *in_buffer)
{
	in_buffer = Serialize::Serialize8(in_buffer, playerInitizeInput.PlayerID);
	in_buffer = Serialize::Serialize8(in_buffer, playerInitizeInput.NameSize);
	for (size_t i = 0; i < playerInitizeInput.NameSize; i++)
		in_buffer = Serialize::Serialize8(in_buffer, playerInitizeInput.Name[i]);
	return in_buffer;
}

char *RepProtocol::DeserializeReadyMSG(char *ptr, PlayerReady &playerReady)
{
	ptr = Serialize::Deserialize16(ptr, playerReady.RoomId);
	return Serialize::Deserialize8(ptr, playerReady.PlayerID);
}

char *RepProtocol::DeserializeControllsMSG(char *ptr, PlayerInput &playerInput)
{
	ptr = Serialize::Deserialize16(ptr, playerInput.RoomId);
	return Serialize::Deserialize16(ptr, playerInput.Controll);
}

char *RepProtocol::SerializeControllsMSG(PlayerInput &playerInput, char *in_buffer)
{
	in_buffer = Serialize::Serialize8(in_buffer, playerInput.PlayerID);
	return Serialize::Serialize16(in_buffer, playerInput.Controll);
}

char *RepProtocol::SerializeGainControlIDMSG(unsigned char player_id, unsigned short world_id, char *in_buffer)
{
	in_buffer = Serialize::Serialize8(in_buffer, player_id);
	return in_buffer = Serialize::Serialize16(in_buffer, world_id);
}

char *VoipProtocol::SerializeMSGType(char *ptr, unsigned char MSGTypes)
{
	return Serialize::Serialize8(ptr, MSGTypes);
}

char *VoipProtocol::DeserializeMSGType(char *ptr, unsigned char &MSGTypes)
{
	return Serialize::Deserialize8(ptr, MSGTypes);
}

char *VoipProtocol::SerializeNoTlKMDify(char *ptr, unsigned char Flag)
{
	return Serialize::Serialize8(ptr, Flag);
}

char *VoipProtocol::DeserializeNoTlKMDify(char *ptr, unsigned char &Flag)
{
	return Serialize::Deserialize8(ptr, Flag);
}